package com.itqf.exceptionhandler;

import com.itqf.exception.UserException;
import org.apache.shiro.authz.UnauthenticatedException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

/**
 * projectName: rbacgp8
 *
 * @author: 赵伟风
 * time: 2021/8/12 11:38
 * description:全年异常处理器
 */
@ControllerAdvice
public class AllExceptionHandler {

    @ExceptionHandler(UserException.class)
    public ModelAndView userExceptionHandler(UserException ex){

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("error");
        modelAndView.addObject("msg", ex.getMessage());

        return modelAndView;
    }

    @ExceptionHandler(UnauthorizedException.class)
    public ModelAndView userExceptionHandler(UnauthorizedException ex){

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("error");
        modelAndView.addObject("msg", "未授权!");

        return modelAndView;
    }


    @ExceptionHandler(UnauthenticatedException.class)
    public ModelAndView userExceptionHandler(UnauthenticatedException ex){

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("error");
        modelAndView.addObject("msg", "未认证!");

        return modelAndView;
    }

}
